//
//  AllocationViewController.m
//  TraineeManagementSystem
//
//  Created by Dhanashree Bodas on 23/01/15.
//  Copyright (c) 2015 Dhanashree Bodas. All rights reserved.
//

#import "AllocationViewController.h"
#import "TraineeTable.h"
#import "Trainee.h"

@interface AllocationViewController ()

@end

@implementation AllocationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


- (void)viewWillAppear:(BOOL)animated
{
    [self loadData];
    [self.allocationTableview reloadData];
    
}


-(void) loadData
{
    TraineeTable *t=[[TraineeTable alloc] init];
    self.tdata=[t listTrainee];
    [self.allocationTableview reloadData];
    
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"allocate"]) {
       
        NSIndexPath *indexPath = [self.allocationTableview indexPathForSelectedRow];
        Trainee *t=[self.tdata objectAtIndex:indexPath.row];
        int tid=t.tid;
        [[segue destinationViewController] setTid:tid];
    }
}


#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _tdata.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    Trainee *t1=[self.tdata objectAtIndex:[indexPath row]];    
    cell.textLabel.text=[t1.fname stringByAppendingFormat:@"   %@",t1.lname];

    
    return cell;
 
}


@end
